package com.shujia.wyh.day16;

/*
        String作为参数传递
        StringBuffer作为参数传递

 */
public class StringBufferDemo9 {
    public static void main(String[] args) {
//        String s1 = "hello";
//        String s2 = "world";
//        System.out.println("s1:" + s1 + ",s2:" + s2); // s1:hello,s2:world
//        change(s1, s2);
//        System.out.println("s1:" + s1 + ",s2:" + s2); // s1: hello ,s2: world

        StringBuffer sb1 = new StringBuffer("hello");
        StringBuffer sb2 = new StringBuffer("world");
        System.out.println("sb1:" + sb1 + ",sb2:" + sb2); //sb1: hello  ,sb2: world
        change(sb1,sb2);
        System.out.println("sb1:" + sb1 + ",sb2:" + sb2); // sb1: hello  ,sb2: worldworld



    }

    // 当StringBuffer作为参数传递的时候，谁进行了操作，谁就发生了变化
    public static void change(StringBuffer sb1,StringBuffer sb2){
        sb1 = sb2;
        sb2 = sb1.append(sb2);
        System.out.println("sb1:" + sb1 + ",sb2:" + sb2); // sb1: worldworld  ,sb2: worldworld
    }

    public static void change(String s1, String s2) {
        s1 = s2;
        s2 = s1 + s2;
        System.out.println("s1:" + s1 + ",s2:" + s2); //s1: world ,s2:worldworld

    }
}
